<!DOCTYPE html>
<html>
<style>
	.sell_cls{
		        border: 1px solid #38d444;
			    padding: 5px;
			    background-color: #7fdc82;
			    border-radius: 5px;
			    color: #fff;
		}
</style>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link href="__INDEX__/css/Phoebe.css" rel="stylesheet" />
		<link href="__INDEX__/css/all.css" rel="stylesheet" />
		<link href="__INDEX__/css/stock.css" rel="stylesheet" />
		<title>卖出</title>
	</head>

	<body style="margin-top: 45px;">
		<header class="mui-bar mui-bar-nav">
			<a href="javascript:history.back(-1)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">卖出</h1>
		</header>
		<!--进货-->
		<div class="stock">
			<form action="">
				<div>
					<span>产品名称 :</span>

					<select name="" id="sel">
						<option value="">请选择产品</option>
						{foreach name="goods" item="gd"}
						<option value="{$gd.goods_id}">{$gd.goods_name} &nbsp; &nbsp; &nbsp;/发行价：{$gd.price}</option>
						{/foreach}
					</select>

				</div>
				<div>
					<div>
						<span>卖出价 :</span>
						<input type="text" id="offer" name="stock_buy_price" onblur="amount(this)" />
					</div>
				</div>
				<div>
					<div>
						<span>卖出数量 :</span>
						<input type="tel" id="stock_num" name="stock_buy_num" />
					</div>

				</div>
				<div class="submit" onclick="return sell();" style="width: 50%;">确认</div>
			</form>
		</div>
		<!--出价记录-->
		<div class="money-list" id="cha">
			<ul>

			</ul>
		</div>
		<!--model-->
		<div class="my-modal">
			<div>
				<h2>进货确认</h2>
				<div>
					<p>产品名称：<span>产品名称</span></p>
					<div>
						<ul>
							<li>进货出价：<span></span></li>
							<li>进货数量：<span></span></li>
						</ul>
					</div>
					<p id="xianyin"></p>
					<div>
						<button class="stock_conf">确认</button>
						<button class="close-stock">取消</button>
					</div>
				</div>
			</div>
		</div>
	</body>

</html>
{include file="public/footer" /}
<script>
	layui.config({
		base: '/public/static/js/'
	}).use('admin');
	var user_id = '{$Think.session.uid}';

	if(user_id == "" || user_id == null) {
		layer.msg("请先登录", {
			icon: 1,
			time: 1000 //2秒关闭（如果不配置，默认是3秒）
		}, function() {
			location.href = "{:url('index/login')}";
		});
	}
	$("#sel").change(function() {
		if($(this).val() != "") {
			var html = "<li> <div style='width:25%;'>用户ID</div> <div style='width:25%;'>出价</div><div style='width:25%;'>数量</div><div style='width:33%;'>操作</div> </li>";
			$.ajax({
				url: "{:url('index/get_bs')}",
				data: {
					goods_id: $(this).val(),
					type: 1,
					order: 'desc'
				},
				success: function(data) {
					var order = data.orders;
					if(order) {
						for(var o in order) {
							html += '<li><div style="width:25%;">' + order[o].uid + '</div><div style="width:25%;">' + order[o].price + '</div>';
							html += '<div style="width:25%;">' + order[o].num + '</div><div style="width:25%;"><a class="sell_cls" href="#" onclick="sellgd(' + order[o].id + ')">出售</a></div></li>';
						}
					}
					$('#cha ul').html(html);
				}

			})
		}
	});

	function sellgd(order_id) {
		var con = layer.confirm('确认操作?', function(index) {
			$.ajax({
				url: "{:url('index/sell_order')}",
				//请求的过程中传递过去的参数 json
				data: {
					order_id: order_id
				},
				//成功了的回调，并且带有返回值
				success: function(data) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if(data.code == 200) {
							location.href = "{:url('member/my_market')}";
						}
					});
				}
			})
		});
	}

	function sell() {
		id = $('#sel').val();
		if(!id) {
			layer.msg('请选择商品！');
		} else if(($('#offer').val()) * 1 == '') {
			layer.msg('请输入价格！');
		} else if(($('#stock_num').val()) == '') {
			layer.msg('请输入卖出数量！');
		} else {
			$.ajax({
				url: "guadan2",
				//请求的过程中传递过去的参数 json
				data: {
					goods_id: id,
					price: $('#offer').val(),
					type: 2,
					num: $('#stock_num').val()
				},
				//成功了的回调，并且带有返回值
				success: function(data) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if(data.code == 200) {
							location.href = "{:url('member/my_market')}";
						}
					});
				}
			})

		}
		return false;
	}

	$(".close-stock").click(function() {
		$(".my-modal").css("display", "none");
	})
</script>
<script>
	var offer = document.getElementById('offer');

	function amount(th) {
		var regStrs = [
			['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
			['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
			['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
			['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
		];
		for(var i = 0; i < regStrs.length; i++) {
			var reg = new RegExp(regStrs[i][0]);
			th.value = th.value.replace(reg, regStrs[i][1]);
		}
	}
</script>